<?php

/**
 * This is the model class for table "account".
 *
 * The followings are the available columns in table 'account':
 * @property integer $id
 * @property string $username
 * @property string $password
 * @property integer $role
 * @property string $firstName
 * @property string $lastName
 * @property string $email
 * @property string $address
 * @property integer $gender
 * @property string $birthday
 * @property string $company
 * @property string $phone
 */
class Account extends CActiveRecord {

    public $conf_password;

    /**
     * Returns the static model of the specified AR class.
     * @return Account the static model class
     */
    public static function model($className=__CLASS__) {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return 'account';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('username, password, conf_password, email', 'required'),
            array('role, gender', 'numerical', 'integerOnly' => true),
            array('username, password, firstName, lastName, email, company', 'length', 'max' => 50),
            array('address', 'length', 'max' => 150),
            array('phone', 'length', 'max' => 20),
            array('birthday', 'safe'),
            array('conf_password', 'compare', 'compareAttribute' => 'password'),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id, username, password, role, firstName, lastName, email, address, gender, birthday, company, phone', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'id' => 'ID',
            'username' => 'Username',
            'password' => 'Password',
            'role' => 'Role',
            'firstName' => 'First Name',
            'lastName' => 'Last Name',
            'email' => 'Email',
            'address' => 'Address',
            'gender' => 'Gender',
            'birthday' => 'Birthday',
            'company' => 'Company',
            'phone' => 'Phone',
            'conf_password' => 'Password'
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('id', $this->id);
        $criteria->compare('username', $this->username, true);
        $criteria->compare('password', $this->password, true);
        $criteria->compare('role', $this->role);
        $criteria->compare('firstName', $this->firstName, true);
        $criteria->compare('lastName', $this->lastName, true);
        $criteria->compare('email', $this->email, true);
        $criteria->compare('address', $this->address, true);
        $criteria->compare('gender', $this->gender);
        $criteria->compare('birthday', $this->birthday, true);
        $criteria->compare('company', $this->company, true);
        $criteria->compare('phone', $this->phone, true);

        return new CActiveDataProvider($this, array(
                    'criteria' => $criteria,
                ));
    }

}